﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PQ.IDA;
using PQ.Model;
using PQ.Helper;
using PQ.Enum;
using System.IO;
using System.Json;
using System.Text.RegularExpressions;

namespace PQ.DA
{
    public class DAUser : IDAUser
    {

        /// <summary>
        /// 日志
        /// </summary>
        private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(typeof(DAUser));

        private string UrlLogin = "http://ptlogin2.qq.com/login?u={0}&p={1}&verifycode={2}&remember_uin=1&aid=1003903&u1=http%3A%2F%2Fweb2.qq.com%2Floginproxy.html%3Fstrong%3Dtrue&h=1&ptredirect=0&ptlang=2052&from_ui=1&pttype=1&dumy=&fp=loginerroralert";
        private string Urllogin2 = "http://d.web2.qq.com/channel/login2";

        //判断 是否需要验证码
        /// <summary>
        /// 判断 是否需要验证码
        /// </summary>
        private string UrlCheck = "http://ptlogin2.qq.com/check?uin={0}&appid={1}&r={2}";
        //验证码 图片的地址
        /// <summary>
        /// 验证码 图片的地址
        /// </summary>
        private string UrlGetImage = "http://captcha.qq.com/getimage?aid={0}&r={1}&uin={2}&vc_type={3}";


        private string 获取即时消息地址 = "http://d.web2.qq.com/channel/poll2?clientid={0}&psessionid={1}&t={2}";

        private readonly string UrlRestraint = "http://aq.qq.com/cn/services/abnormal/abnormal_direc_release";

        private static readonly string[] AVATAR_SERVER_DOMAINS = new[] { "http://face1.qun.qq.com/", 
            "http://face2.qun.qq.com/", "http://face3.qun.qq.com/", 
            "http://face4.qun.qq.com/", "http://face5.qun.qq.com/", "http://face6.qun.qq.com/", "http://face7.qun.qq.com/", "http://face8.qun.qq.com/", "http://face9.qun.qq.com/", "http://face10.qun.qq.com/" };
        private static readonly string RefUrl = "http://s.web2.qq.com/proxy.html?v=20101025002";

        private static string 好友发送消息 = "http://d.web2.qq.com/channel/send_msg2";

        private static HttpHelper httpHelper = new HttpHelper();

        //登陆
        /// <summary>
        /// http://ptlogin2.qq.com/login?u=1497414463&p=74DA5C69E840DFB80A43527E643A679E&verifycode=udyb&remember_uin=1&aid=1003903&u1=http%3A%2F%2Fweb2.qq.com%2Floginproxy.html%3Fstrong%3Dtrue&h=1&ptredirect=0&ptlang=2052&from_ui=1&pttype=1&dumy=&fp=loginerroralert
        ///ptuiCB('0','0','http://web2.qq.com/loginproxy.html?strong=true','0','登录成功！');
        ///ptuiCB('0','0','http://web2.qq.com/loginproxy.html?strong=true','0','登录成功！');
        /// result结果: ptuiCB('24','0','','0','参数非法(3330278672)');
        /// </summary>
        /// <param name="userEntity"></param>
        /// <returns></returns>
        public UserEntity Login(UserEntity userEntity)
        {
            //string s = Helpers.StrConvUrlEncoding("我爱中国,abc", "utf-8");
            //%e6%88%91%e7%88%b1%e4%b8%ad%e5%9b%bd%2cabc
            string url = String.Format(UrlLogin, userEntity.UserName, userEntity.Password, userEntity.VerifyCode);
            //httpHelper.CookieContainer = userEntity.Cookie;
            string result = httpHelper.GetHtml(url);

            string state = "";
            if (result != "")
            {
                Log.AddResult("login.txt", DateTime.Now + result + Environment.NewLine);
                MatchData md = new MatchData("\\('", "',", result);
                md.Match();
                state = md.Result.Replace("('", "").Replace("',", "");

            }
            if (state == "0")
            {
                userEntity.Status = LoginStatus.Logined;
                if (!InitWebQQ(userEntity))
                    userEntity.Status = LoginStatus.loginwang;
            }
            else if (state == "4")
            {
                userEntity.Status = LoginStatus.VerifyCodewang;
            }
            else
            {
                userEntity.Status = LoginStatus.loginwang;
            }

            if (result.Contains("登录成功"))
            {
                try
                {
                    string refUrl = result.Replace("ptuiCB('0','0','", "").Replace("','1','登录成功！');", "");
                    this.SaveUser(userEntity);
                    
                    if (refUrl != "")
                    {
                        if (ReleaseRestraint(refUrl, userEntity))
                        {
                            userEntity.Status = LoginStatus.Logined;
                            if (!InitWebQQ(userEntity))
                                userEntity.Status = LoginStatus.loginwang;
                        }
                    }
                }
                catch (Exception)
                {
                    userEntity.Status = LoginStatus.PasswordWang;
                }
            }
            return userEntity;
        }

        /// <summary>
        /// 获取 放在 文件中的用户信息
        /// </summary>
        /// <returns></returns>
        public List<UserEntity> GetUsers()
        {
            List<UserEntity> list = null;
            try
            {
                string line;
                if (File.Exists("users.ini"))
                {
                    //using (System.IO.StreamReader file = new System.IO.StreamReader("users.ini", Encoding.GetEncoding("gbk")))
                    //{
                    //    while ((line = file.ReadLine()) != null)
                    //    {
                    //        list.Add(SerializeHelper.BinaryDeserialize<UserEntity>(line));
                    //    }
                    //}
                    object o = Log.ReadGraph("users.ini");
                    list=SerializeHelper.BinaryDeserialize<List<UserEntity>>(o != null ? o.ToString() : string.Empty);
                }
            }
            catch (Exception)
            {
            }
            if (list == null)
            {
                return new List<UserEntity>();
            }
            return list;
        }

        private void SaveUser(UserEntity userEntity)
        {
            List<UserEntity> list = GetUsers();
            bool b = false;
            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].Uin == userEntity.Uin)
                    {
                        list[i] = userEntity;
                        b = true;
                        break;
                    }
                }
            }
            if (!b)
            {
                list.Add(userEntity);
            }
            
            Log.Logs(SerializeHelper.BinarySerialize(list) + Environment.NewLine, "users.ini");
        }

        /// <summary>
        /// result:{"retcode":0,"result":{"uin":1497414463,"cip":455493866,"index":1078,"port":53938,"status":"online","vfwebqq":"54c035a0b5f60cf8fd67949092b4d46a55bbf2a40a082d3dfd0f26fca970f502485acc634c5971e3","psessionid":"8368046764001e636f6e6e7365727665725f7765627171403137322e32372e3138312e3835000023d500000962036e04003fbb40596d0000000a407751734846774f42326d0000002854c035a0b5f60cf8fd67949092b4d46a55bbf2a40a082d3dfd0f26fca970f502485acc634c5971e3","user_state":0,"f":0}}
        /// {"retcode":100000,"errmsg":""}
        /// </summary>
        /// <param name="userEntity"></param>
        /// <returns></returns>
        private bool InitWebQQ(UserEntity userEntity)
        {
            userEntity.ClientId = WebQQUtil.GenerateClientID();
            string postData = string.Format(
                "r=%7B%22status%22%3A%22%22%2C%22ptwebqq%22%3A%22{0}%22%2C%22passwd_sig%22%3A%22%22%2C%22clientid%22%3A%22{1}%22%2C%22psessionid%22%3Anull%7D"
                                            , userEntity.ptwebqq, userEntity.ClientId);
            string result = httpHelper.GetHtml(Urllogin2, postData, true, Urllogin2);
            try
            {
                JsonObject jsonObject = (JsonObject)JsonValue.Parse(result);
                if (jsonObject["retcode"].ToString() == "0")
                {
                    JsonValue item = jsonObject["result"];
                    userEntity.Key = item["vfwebqq"];
                    userEntity.Psessionid = item["psessionid"];
                    return true;
                }
               
            }
            catch (Exception)
            {
            }
            userEntity.Key = "";
            return false;

            //userEntity.Key = Utils.getStringByRegex(result, "(\"vfwebqq\":\")(?<key>.+?)(\",)", "key", 0);
            //userEntity.Psessionid = Utils.getStringByRegex(result, "(\"psessionid\":\")(?<id>.+?)(\"}})", "id", 0);
        }

        //给好友发送消息
        /// <summary>
        /// 给好友发送消息
        /// {"retcode":0,"result":"ok"}
        ///</summary>
        /// <returns></returns>
        public bool SendFriendMessage(MessageModel messageModel,UserEntity userEntity)
        {
            string result = httpHelper.GetHtml(好友发送消息, messageModel.Content, true,
                "http://web2-b.qq.com/proxy.html?v=20101025002");
            
            if (result.Contains("retcode\":0"))
                return true;
            else
                return false;
        }

         
        

        /// <summary>
        /// 判断是否需要验证码
        /// http://ptlogin2.qq.com/check?uin=415516174&appid=15000101&r=0.8178552857537984
        /// uin为QQ号码
        /// appid
        /// r为16位随机小数
        ///返回格式 ptui_checkVC('0','!XGB');  
        ///ptui_checkVC('1','d3831928a037b4fb5a5336936989e6a607a4edb0ed6da139');
        ///ptui_checkVC('1','e705ecf935c0a7c103673b5424de20f24000930e24095b59');
        ///0代表不需要输入验证码，验证码为！XGB
        ///1代表需要验证码，后边会跟48位的密文，应该是个算子，在获取验证码的时候要用到
        /// </summary>
        /// <returns>返回为需要验证码</returns>
        public bool IsNeedVerifyCode(UserEntity userEntity)
        {

           // string s = Helpers.StrConvUrlEncoding("我爱中国,abc", "utf-8");
            //%e6%88%91%e7%88%b1%e4%b8%ad%e5%9b%bd%2cabc
            //%E6%88%91%E7%88%B1%E4%B8%AD%E5%9B%BD%2C%61%62%63
             httpHelper.CookieContainer = userEntity.Cookie;
            string url = String.Format(UrlCheck, userEntity.UserName, userEntity.appid,
                Utils.getRadomNum().ToString());
            string result = httpHelper.GetHtml(url);
            if (result.Contains("\'0\'"))
            {
                string vc = "";
                try
                {
                    vc = result.Substring(result.LastIndexOf("\'") - 4, 4);
                }
                catch (Exception)
                {
                }
                userEntity.VerifyCode = vc;
                return false;
            }
            else if (result.Contains("\'1\'"))
            {
                string vc = "";
                try
                {
                    vc = result.Substring(result.LastIndexOf("\'") - 48, 48);
                }
                catch (Exception)
                {

                }
                userEntity.VerifyCode32 = vc;
                return true;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// 返回验证码的图片流
        /// 验证码的获取地址的构成需要48位的算子，需要在判断是否需要验证码时获取
        /// </summary>
        /// <returns></returns>
        public Stream GetVerifyCodePicStream(UserEntity userEntity)
        {
            System.IO.Stream result = null;
            try
            {
                string url = String.Format(UrlGetImage,
                    userEntity.appid, Utils.getRadomNum().ToString(), userEntity.UserName,
                    userEntity.VerifyCode32);
                result = httpHelper.GetStream(url);
            }
            catch (Exception)
            {

            }
            return result;
        }

        /// <summary>
        /// 解除限制
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public bool ReleaseRestraint(String url, UserEntity userEntity)
        {
            httpHelper.GetHtml(url);
            string result = httpHelper.GetHtml(UrlRestraint);
            if (result.Contains("您的QQ帐号不能直接解除登录限制"))
            {
                return false;
            }
            else
            {
                return true;
            }
        }


        /// <summary>
        /// 获取用户的详细信息
        /// </summary>
        /// <param name="userEntity">UserEntity</param>
        /// <returns></returns>
        public UserEntity GetSingleInfo(UserEntity userEntity)
        {
            string url = string.Format("http://web2-b.qq.com/api/get_single_info?tuin={0}&t={1}", userEntity.Uin,
                                       WebQQUtil.GetTime(DateTime.Now));
            string html = httpHelper.GetHtml(url);
            var json = (JsonObject)JsonValue.Parse(html);
            int retcode = json["retcode"];
            if (retcode == 0)
            {
                var item = (JsonObject)json["result"];
                //userEntity.Status = QQHelper.ParseOnlineStatus(item["stat"]);
                userEntity.NickName = item["nick"];
                //userEntity.Country = item["country"];
                // userEntity.PersonalElucidation = item["province"];
                //userEntity.City = item["city"];
                //userEntity.Sex = item["gender"];
                //userEntity.Face = item["face"];
                //var birthday = (JsonObject)item["birthday"];
                //int year = birthday["year"];
                //int month = birthday["month"];
                //int day = birthday["day"];
                //userEntity.Birthday = new DateTime(year, month, day);
                //userEntity.Allow = item["allow"];
                //userEntity.Blood = item["blood"];
                //userEntity.ShengXiao = item["shengxiao"];
                //userEntity.Constel = item["constel"];
                userEntity.TelePhone = item["phone"];
                userEntity.MPhone = item["mobile"];
                userEntity.Email = item["email"];
                //userEntity.Occupation = item["occupation"];
                //userEntity.College = item["college"];
                userEntity.HomeUrl = item["homepage"];
                userEntity.PersonalElucidation = item["personal"];

            }
            return userEntity;
        }

        /// <summary>
        /// 退出
        /// </summary>
        public void LogOut(UserEntity userEntity)
        {
            string url = "http://web2-b.qq.com/channel/login";
            string postData = string.Format("r=%7B%22status%22%3A%22%22%2C%22ptwebqq%22%3A%22{0}%22%2C%22passwd_sig%22%3A%22%22%2C%22clientid%22%3A%22{1}%22%7D"
                                            , userEntity.ptwebqq, userEntity.ClientId);
            string result = httpHelper.GetHtml(url, postData, true, url);
            Log.AddResult("logOut.txt", DateTime.Now + ":" + result + Environment.NewLine);
        }

        /// <summary>
        /// 隐身
        /// </summary>
        public void ChangeStatus(UserStatusEnum userStatusEnum, UserEntity userEntity)
        {
            string state = "online";
            switch (userStatusEnum)
            {
                case UserStatusEnum.Online:
                    state = "online";
                    break;
                case UserStatusEnum.Away:
                    state = "away";
                    break;
                case UserStatusEnum.Hidden:
                    state = "hidden";
                    break;
                case UserStatusEnum.Offline:
                    state = "offine";
                    break;
                default:
                    state = "online";
                    break;
            }
            string url = string.Format("http://web2-b.qq.com/channel/change_status?newstatus={0}&clientid={1}&psessionid={2}&t={3}", state,
                userEntity.ClientId, userEntity.Psessionid, WebQQUtil.GetTime(DateTime.Now));
            string result = httpHelper.GetHtml(url);
        }

        //获取好友及好友分组
        /// <summary>
        /// 获取好友及好友分组
        /// {"retcode":0,"result":
        /// {"categories":[{"index":1,"name":"\u670B\u53CB"},{"index":2,"name":"\u5BB6\u4EBA"},
        /// {"index":3,"name":"\u540C\u5B66"}],
        /// "friends":[{"uin":605064709,"categories":0}],
        /// "info":[{"uin":605064709,"nick":
        /// "\u5BFB\u627E\u98CE\u7684\u611F\u89C9","face":525,"flag":13107776}],
        /// "marknames":[]}}
        /// 
        /// </summary>
        /// <returns></returns>
        public UserEntity GetUserFriends(UserEntity userEntity)
        {
            userEntity.Categories = new Dictionary<int, string>();
            userEntity.FriendsDic = new Dictionary<string, FriendModel>();
            string url = "http://web2-b.qq.com/api/get_user_friends";
            string data = string.Format("r=%7B%22vfwebqq%22%3A%22{0}%22%7D", userEntity.Key);
            string result = httpHelper.GetHtml(url, data, true, url);

            try
            {
                JsonObject jsonObject = (JsonObject)JsonValue.Parse(result);
                if (jsonObject["retcode"].ToString() == "0")
                {
                    JsonObject categories = (JsonObject)jsonObject["result"];
                    userEntity.Categories.Add(0,"我的好友");
                    foreach (JsonObject item in categories["categories"])
                    {
                        userEntity.Categories.Add(Convert.ToInt32(item["index"].ToString()), 
                         item["name"]);
                    }
                    foreach (JsonObject item in categories["friends"])
                    {
                        string uin=item["uin"].ToString();
                       int categoriesId= Convert.ToInt32(item["categories"].ToString());
                        if (userEntity.Categories.Keys.Contains(categoriesId))
                        {
                            FriendModel fm = new FriendModel();
                            fm.CategoriesId = categoriesId;
                            fm.Uin = uin;
                            userEntity.FriendsDic.Add(uin, fm);
                        }
                        else
                        {
                            FriendModel fm = new FriendModel();
                            fm.Uin = uin;
                            fm.CategoriesId = categoriesId;
                            userEntity.FriendsDic.Add(uin, fm);
                        }
                    }

                    foreach (JsonObject item in categories["info"])
                    {
                        string uin = item["uin"].ToString();

                        if (userEntity.FriendsDic.Keys.Contains(uin))
                        {
                            FriendModel fm= userEntity.FriendsDic[uin];
                            fm.Nick = item["nick"].ToString();
                            fm.FaceImg = item["face"].ToString();
                            fm.Flag = item["flag"].ToString();
                        }
                    }
                    
                }

            }
            catch (Exception)
            {
                throw;
            }
            //Regex group = new Regex("({\"index\":)(?<index>[0-9]{1,2}?)(,\"name\":\")(?<name>.+?)(\"})");
            //foreach (Match item in group.Matches(result))
            //{
            //    userEntity.Groups.Add(Convert.ToInt32(item.Groups["index"].Value), Utils.ConvertUnicodeStringToChinese(item.Groups["name"].Value));
            //}

            //Regex friend = new Regex("({\"uin\":)(?<uin>[0-9]{5,11}?)(,\"categories\":)(?<id>[0-9]{1,2}?)(})");
            //foreach (Match item in friend.Matches(result))
            //{
            //    FriendModel f = new FriendModel();
            //    f.Uin = item.Groups["uin"].Value;
            //    f.GroupId = Convert.ToInt32(item.Groups["id"].Value);
            //    userEntity.FriendsDic.Add(f.Uin, f);
            //}

            //Regex info = new Regex("({\"uin\":)(?<uin>[0-9]{5,11}?)(,\"nick\":\")(?<nick>.+?)(\",\"face\":)(?<face>.+?)(,\"flag\":)(?<flag>.+?)(})");
            //foreach (Match item in info.Matches(result))
            //{
            //    if (userEntity.FriendsDic.Keys.Contains(item.Groups["uin"].Value))
            //    {
            //        userEntity.FriendsDic[item.Groups["uin"].Value].Nick = Utils.ConvertUnicodeStringToChinese(item.Groups["nick"].Value);
            //        userEntity.FriendsDic[item.Groups["uin"].Value].FaceImg = item.Groups["face"].Value;

            //    }
            //}
            return userEntity;
        }

        /// <summary>
        /// 获取即时消息
        /// {"retcode":0,"result":[{"poll_type":"message","value":{"msg_id":3879,"from_uin":1990165201,"to_uin":404313364,"msg_id2":547813,"msg_type":9,"reply_ip":2886742903,"time":1304699571,"content":[["font",{"size":12,"color":"8000ff","style":[0,0,0],"name":"\u5B8B\u4F53"}],"\u5417\u770B\u770B\u561B\u770B",["face",6]],"raw_content":"\u00C2\u03FD3F\u00B4\u00C2\uFFF4\u0014G"}},{"poll_type":"buddies_status_change","value":{"uin":1945321301,"status":"online","client_type":1}},{"poll_type":"buddies_status_change","value":{"uin":3882943518,"status":"online","client_type":1}},{"poll_type":"buddies_status_change","value":{"uin":1222057066,"status":"offline","client_type":1}}]}
        /// </summary>
        public List<MessageModel> GetMessage(UserEntity userEntity)
        {
            List<MessageModel> messageList = new List<MessageModel>();
            try
            {
                string url = string.Format(获取即时消息地址,
                userEntity.ClientId, userEntity.Psessionid, WebQQUtil.GetTime(DateTime.Now).ToString());
                string result = httpHelper.GetHtml(url);
                if (result != "")
                {
                    JsonObject message = (JsonObject)JsonValue.Parse(result);

                    if (message["retcode"].ToString() == "0")
                    {

                        foreach (JsonObject item in message["result"])
                        {
                            string type = item["poll_type"].ToString().Replace("\"", "");
                            MessageModel mm = new MessageModel();
                            switch (type)
                            {
                                case "message":
                                    JsonValue jv = item["value"];
                                    mm.MessageType = MessageTypeEnum.Message;
                                    mm.From_uin = jv["from_uin"].ToString();
                                    mm.Content = jv["content"].ToString();
                                    mm.Value = jv.ToString();
                                    messageList.Add(mm);
                                    break;
                                case "system_message":
                                    //InitAddFriendEvent(item);
                                    break;
                                case "group_message":
                                    JsonValue jv_group = item["value"];
                                    mm.MessageType = MessageTypeEnum.Group_message;
                                    mm.Group_code = jv_group["group_code"].ToString();
                                    mm.Send_uin = jv_group["send_uin"].ToString();
                                    mm.Content = jv_group["content"].ToString();
                                    mm.Value = jv_group.ToString();
                                    messageList.Add(mm);
                                    break;
                                case "buddies_status_change":
                                    JsonValue jv_buddies_status_change = item["value"];
                                    mm.MessageType = MessageTypeEnum.Buddies_status_change;
                                    mm.Uin = jv_buddies_status_change["uin"].ToString();
                                    mm.Status = jv_buddies_status_change["status"].ToString();
                                    mm.Client_type = jv_buddies_status_change["client_type"].ToString();
                                    mm.Value = jv_buddies_status_change.ToString();
                                    messageList.Add(mm);
                                    //                                ClientTypeEnum
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    else
                    {
                        MessageModel notMessage = new MessageModel();
                        notMessage.MessageType = MessageTypeEnum.NotMessage;
                        notMessage.Value = result;
                        messageList.Add(notMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageModel errorMessage = new MessageModel();
                errorMessage.MessageType = MessageTypeEnum.NotMessage;
                errorMessage.Value = ex.Message;
                messageList.Add(errorMessage);
                Log.AddResult("GetMessage.txt", DateTime.Now + ex.Message + Environment.NewLine);
            }
            return messageList;
        }

        /// <summary>
        /// 获取头像服务器
        /// qq%10+1 就是服务器地址
        /// </summary>
        /// <param name="qq"></param>
        /// <returns></returns>
        private string GetFaceServer(int qq)
        {
            return AVATAR_SERVER_DOMAINS[qq % 10];

        }

        /// <summary>
        /// 获取用户头像
        /// http://face7.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=1760958816&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face6.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=481863815&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face7.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=3120089006&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face9.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=3175422448&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face5.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=3670653394&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face7.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=3763603356&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face1.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=2809735330&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face2.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=1759436621&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face6.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=3808588845&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face8.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=2601350547&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face7.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=2452658056&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face9.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=2396582058&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face7.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=295011376&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face6.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=332622725&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face6.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=1109959875&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face4.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=2454297693&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face3.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=414528302&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// http://face1.qun.qq.com/cgi/svr/face/getface?cache=0&type=1&fid=0&uin=896700080&vfwebqq=b49ed05caff42a2494ab3681488d717584f1568c83cf3113a1a1f20b2d13b96520e8858e71964dbc
        /// </summary>
        /// <param name="qq"></param>
        /// <returns></returns>
        public System.IO.Stream GetUserAvatar(string uin)
        {
            return httpHelper.GetStream(GetFaceServer(Convert.ToInt32(uin)) +
                "cgi/svr/face/getface?cache=0&type=1&fid=0&uin=" + uin);
        }
    }
}
